﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CNotebook;
using CNotebook.Inventory;
using NotebookS2.Inventory.Transactions;

namespace NotebookS2
{
    public partial class ReceivingTransfer : Form
    {
        public ReceivingTransfer()
        {
            InitializeComponent();
        }
        public string ConnectionString { get; set; }

        void BindWarehouse()
        {
            WarehouseManager oManager = new WarehouseManager();
            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();
            DataTable oTable = new DataTable();

            oTable = oManager.GetWarehouse();


            cboWarehouse.Visible = false;
            cboWarehouse.Properties.DataSource = oTable;
            cboWarehouse.Properties.DisplayMember = "Dscription";
            cboWarehouse.Properties.ValueMember = "Code";

            DevExpress.XtraEditors.Controls.LookUpColumnInfo col;

            col = new DevExpress.XtraEditors.Controls.LookUpColumnInfo("Code", "Code", 100);

            col.SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;


            cboWarehouse.Properties.Columns.Add(col);

            col = new DevExpress.XtraEditors.Controls.LookUpColumnInfo("Dscription", "Dscription", 100);

            cboWarehouse.Properties.Columns.Add(col);

            cboWarehouse.Visible = true;


            oManager.Close();
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            DevExpress.XtraSplashScreen.SplashScreenManager.ShowForm(typeof(WaitForm4));
            
            try
            {
                WTManager oManager = new WTManager();

                oManager.ConnectionString = this.ConnectionString;
                oManager.Open();
                DataTable dt = oManager.GetTransferForReceiving(cboWarehouse.EditValue.ToString());
                oManager.Close();

                
                gridControl1.DataSource = dt;
                gridControl1.Refresh();
            }
            catch
            {
            }

            DevExpress.XtraSplashScreen.SplashScreenManager.CloseForm();
        }

        private void ReceivingTransfer_Load(object sender, EventArgs e)
        {
            BindWarehouse();
        }

        private void txtDocNum_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            WHTransferRecvd oForm = new WHTransferRecvd();
            string sDocNumber = gridView1.GetRowCellValue(gridView1.FocusedRowHandle , gridView1.Columns["DOCNUM"]).ToString();
            oForm.ConnectionString = this.ConnectionString;
            oForm.OpenDocument(sDocNumber);
            oForm.MdiParent = this.MdiParent;
            oForm.Show();
        }
    }
}
